#include"Teacher.h"
#include<stdio.h>
#include<string.h>


void InitTeacher(Teach* t , int id, const char* name )
{
    t->size = 0;
    t->id = id;
    strcpy(t->Name,name);
}


void AddStudent(Teach*t,int StuID,const char* StuName)
{
    if(t->size >= 10)
    {
        printf("已经上限");
    
    }
    t->s[t->size].id = StuID;
    strcpy(t->s[t->size].Name,StuName);
    t->size++;
}

void RemoveByIndex(Teach*t,int Index)
{
    if(Index<0 || Index >= t->size)
    {
        printf("删除失败\n");
        return ;
    }

    for(int i= Index; i < t->size ; i++)
    {
        t->s[i] = t->s[i+1];    
    }

}


void RemoveStudent(Teach*t,void* data , bool (*IsEqual)(void*,void*))
{
    for(int i=0;i<t->size;i++)
    {
        if(IsEqual((&t->s[i]),data))  //回调函数： 函数以参数形式传递给另一个函数
        {
            RemoveByIndex(t,i);
            t->size--; 
            i--; 
        }
    } 
}


// void RemoveStuByName(Teach*t,const char* name)
// {
//     for(int i=0;i<t->size;i++)
//     {
//         if(strcmp(t->s[i].Name,name) == 0 )
//         {
//             RemoveByIndex(t,i);
//             t->size--; 
//             i--; 
//         }
//     } 
// }


void PrintTeacher(Teach*t)
{
    printf("Teacherid = %d  TeacherName = %s \n",t->id,t->Name);
    
    for(int i=0;i < t->size;i++)
    {
        printf("Student id = %d,Student Name = %s\n",t->s[i].id,t->s[i].Name);
    }
}
